package com.sunday.volunteer.adapter;

import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sunday.volunteer.R;
import com.sunday.volunteer.entity.Activity;
import com.sunday.volunteer.entity.Member;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by admin on 2017/1/10.
 */

public class RakingAdapter extends RecyclerViewAdapter {

    public RakingAdapter(List list, int layout) {
        super(list, layout);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(View itemView, int viewType) {
        return new ViewHolder(itemView);
    }

    public class ViewHolder extends MyViewHolder {
        @Bind(R.id.name)
        TextView name;
        @Bind(R.id.logo)
        ImageView logo;
        @Bind(R.id.type)
        TextView type;
        @Bind(R.id.hours)
        TextView hours;
        @Bind(R.id.number)
        TextView number;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(onClickListener);
        }

        @Override
        public void bind(MyViewHolder holder, Object object, int position) {
            Member item = (Member) object;
            setText(name, item.getName());
            setText(type, item.getUserTypeStr());
            setText(hours, item.getHours() + "h");
            setImage( logo ,item.getLogo() ,80 ,80);

            if(position == 0){
                Drawable drawable = holder.itemView.getResources().getDrawable(R.mipmap.ranking_no1);
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                number.setCompoundDrawables(drawable, null, null, null);
            }else if(position == 1){
                Drawable drawable = holder.itemView.getResources().getDrawable(R.mipmap.ranking_no2);
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                number.setCompoundDrawables(drawable, null, null, null);
            }else if(position == 2){
                Drawable drawable = holder.itemView.getResources().getDrawable(R.mipmap.ranking_no3);
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                number.setCompoundDrawables(drawable, null, null, null);
            }else {
                setText(number, position+1);
                number.setCompoundDrawables(null, null, null, null);
            }


        }
    }
}
